package com.virtual.repository.common.managers;

import java.util.Collection;

import com.virtual.repository.common.queries.Query;

/**
 * An abstract class for all Objects, which will manage the repository
 * @author kchaber
 */
public abstract class AbstractRepositoryManager {
	
	/**
	 * The query manager reference
	 */
	protected AbstractQueryManager queryManager;
	
	public AbstractRepositoryManager() {
		//default query manager
		this.queryManager = new QueryManager();
	}
	
	/**
	 * Initializes the repository manager by reading the configuration and setting required resources
	 * @param configFilePath the path to the configuration file
	 */
	public abstract void initialize(String configFilePath);
	
	
	/**
	 * Releases all resources, especially disconnects opened connections
	 */
	public abstract void release();
	
	/**
	 * Executes the query, asking for possible multiple results.
	 * @param query the <code>Query</code> to be executed.
	 * @return a <code>Collection</code> of requested objects.
	 */
	public abstract <TYPE extends Object> Collection<TYPE> executeQuery(Query query) throws Exception;
	
	/**
	 * Executes the query, asking for a single result only.
	 * @param query the <code>Query</code> to be executed.
	 * @return the single result matching the query.
	 */
	public abstract <TYPE extends Object> TYPE executeQueryForSingleObject(Query query) throws Exception;


	public AbstractQueryManager getQueryManager() {
		return queryManager;
	}


	public void setQueryManager(AbstractQueryManager queryManager) {
		this.queryManager = queryManager;
	}
}
